﻿using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Trippy.Abilities;
using Trippy.Animation;
using Trippy.Camera;
using Trippy.CollidableGameComponents.Agents;
using Trippy.CollidableGameComponents.Events;
using Trippy.CollidableGameComponents.Objects;
using Trippy.CollidableGameComponents.Projectiles;
using Trippy.Effects;
using Trippy.Scenery;

namespace Trippy.Levels
{
    class BossFight1 : Level
    {
        public BossFight1(TrippyGame game, Hero hero)
            : base(game, hero)
        {
            TopPadding = 2000f;
            BottomPadding = 2000f;
            RightPadding = 2000f;
            LeftPadding = 2000f;
            Friction = 0.85f;
            UIColor = Color.White;

            if (hero == null)
            {
                Hero = new Hero(this);
            }

            Generate();
            UpdateBounds();
        }

        public override void Initialize()
        {
            Background = Game.Content.Load<Texture2D>("Background/forest");
            MediaPlayer.Play(Game.battleSong);
            MediaPlayer.IsRepeating = true;
            base.Initialize();
        }

        protected override void Generate()
        {
            Random random = new Random();

            EventManager eventManager = new EventManager(this);
            Add(eventManager);

            PowerUp p = new PowerUp(this, new Abilities.Fly(this));
            p.Position = new Vector2(-250, -700);
            Add(p);

            p = new PowerUp(this, new Abilities.Fire(this));
            p.Position = new Vector2(250, -700);
            Add(p);

            p = new PowerUp(this, new Abilities.Invincibility(this, 10f));
            p.Position = new Vector2(100, -700);
            Add(p);

            p = new PowerUp(this, new Abilities.Rocket(this));
            p.Position = new Vector2(-100, -700);
            Add(p);


            var topBeam = new UnpenetrableBeam(this);
            topBeam.Position = new Vector2(0f, -500f);
            topBeam.Scale = new Vector2(.5f);
            Add(topBeam);



            WoodBeam beam = new WoodBeam(this);
            beam.Position = new Vector2(0f, 0f);
            beam.Scale = new Vector2(.2f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-500f, 0f);
            beam.Scale = new Vector2(.3f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(500f, 0f);
            beam.Scale = new Vector2(.3f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Rocket(this));
            p.Position = new Vector2(1150, -200);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(1150f, 0f);
            beam.Scale = new Vector2(.45f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(1150f, 0f);
            beam.Scale = new Vector2(.45f);
            Add(beam);


            p = new PowerUp(this, new Abilities.Invincibility(this, 10f));
            p.Position = new Vector2(-400, 800);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-400f, 1000f);
            beam.Scale = new Vector2(.4f);
            Add(beam);




            beam = new WoodBeam(this);
            beam.Position = new Vector2(400f, 1000f);
            beam.Scale = new Vector2(.4f);
            Add(beam);

//             for (int j = 20; j > -20; j = j - 3)
//             {
//                 for (int i = -18 + j; i < 18 - j; i++)
//                 {
//                     WoodBox box = new WoodBox(this);
//                     box.Position = new Vector2(i * 104 + (j % 2) * 54, 760 + j * 52);
//                     box.Scale = new Vector2(.2f);
//                     Add(box);
//                 }
//             }

            beam = new WoodBeam(this);
            beam.Position = new Vector2(300f, 350f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Rocket(this));
            p.Position = new Vector2(-300, 150);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-300f, 350f);
            beam.Scale = new Vector2(.15f);
            Add(beam);


            p = new PowerUp(this, new Abilities.Fire(this));
            p.Position = new Vector2(600, 150);
            Add(p);


            beam = new WoodBeam(this);
            beam.Position = new Vector2(600f, 350f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-600f, 350f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(900f, 500f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Fire(this));
            p.Position = new Vector2(-900, 300);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-900f, 500f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Invincibility(this, 10f));
            p.Position = new Vector2(700, 450);
            Add(p);


            beam = new WoodBeam(this);
            beam.Position = new Vector2(700f, 650f);
            beam.Scale = new Vector2(.15f);
            Add(beam);



            p = new PowerUp(this, new Abilities.Scry(this));
            p.Position = new Vector2(-700, 550);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-700f, 650f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(1200f, 650f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-1200f, 650f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Fly(this));
            p.Position = new Vector2(1500, 600);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(1500f, 800f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-1500f, 800f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Scry(this));
            p.Position = new Vector2(1200, 750);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(1200f, 950f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-1200f, 950f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(1000f, 1100f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-1000f, 1100f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(800f, 1250f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-800f, 1250f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(600f, 1400f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-600f, 1400f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(400f, 1550f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(-400f, 1550f);
            beam.Scale = new Vector2(.15f);
            Add(beam);

            p = new PowerUp(this, new Abilities.Fly(this));
            p.Position = new Vector2(0, 1500);
            Add(p);

            beam = new WoodBeam(this);
            beam.Position = new Vector2(0f, 1700f);
            beam.Scale = new Vector2(.4f);
            Add(beam);

           
            Ian ian = new Ian(this);
            ian.Position = new Vector2(0, 1500);
            Add(ian);

            SpawnPoint = new Vector2(0, -700);
            Gravity = TrippyConstants.World.Gravity;
            Hero.Acceleration = Gravity;
            Hero.Position = SpawnPoint;
            Add(Hero);

            Weather w = new Weather(this, 500f, 8f, 20f, 90f, new Vector2(.2f));
            Add(w);

            Camera = new TrippyCamera(this, Hero);
            Add(Camera);

            base.Generate();
        }
    }
}
